<template>
	<view class="cu-modal" :class="searchModal.type != '' ? 'show' : ''" @tap="hideModal">
		<view class="cu-dialog" v-show="searchModal.type == 'text'" @tap.stop="">
			<view class="bg-white content text-bold text-pink padding-tb text-xl">小聚超级搜</view>
			<view class="padding text-left text-lg">{{ searchContent }}</view>
			<view class="cu-bar bg-white justify-around action">
				<button class="cu-btn round bg-gray btnWidth" hover-class="none" @tap="hideModal">取 消</button>
				<button class="cu-btn round bg-pink btnWidth" hover-class="none" @tap="search">搜 索</button>
			</view>
		</view>
		<view class="cu-dialog" v-show="searchModal.type == 'link'" @tap.stop="">
			<view class="bg-white content text-bold text-pink padding-tb text-xl">小聚猜您想买</view>
			<view class="flex flex-wrap padding-tb">
				<view class="basis-sm imgItem padding-left-sm"><image :src="searchModal.pItem.pictUrl" class="picItem" mode="aspectFit" lazy-load /></view>
				<view class="basis-df padding-left-sm">
					<view class="titleItem">{{ searchModal.pItem.title }}</view>
					<view class="juanInfo" @tap="goShare">分享 赚￥{{ searchModal.pItem.commissionAmount | Fixed2 }}</view>
					<view class="text-red text-bold text-xl flex justify-start margin-top-sm">￥{{ searchModal.pItem.zkFinalPrice | Fixed2 }}</view>
				</view>
			</view>
			<view class="cu-bar bg-white justify-around action" @tap.stop="">
				<button class="cu-btn round line-orange btnHeight" hover-class="none" @tap="goProduct">查看详情</button>
				<!-- #ifdef APP-PLUS -->
				<button class="cu-btn round bg-pink btnHeight" hover-class="none" @tap="navTaobao">
					购买省￥{{ searchModal.pItem.commissionAmount, searchModal.pItem.couponAmount | commissionCoupon }}
				</button>
				<!-- #endif -->
				<!-- #ifdef MP-WEIXIN -->
				<button class="cu-btn round bg-pink btnHeight" hover-class="none" @tap="copyWord">复制淘口令</button>
				<!-- #endif -->
			</view>
		</view>
		<view class="cu-dialog" v-show="searchModal.type == 'alert'" @tap.stop="">
			<view class="bg-white content text-bold text-pink padding-tb text-xl">小聚未搜索到以下内容</view>
			<view class="padding text-left text-lg">{{ searchContent }}</view>
			<view class="cu-bar bg-white justify-around action"><button class="cu-btn round bg-gray btnWidth" @tap="hideModal" hover-class="none">确 定</button></view>
		</view>
		<view class="cu-dialog" v-show="searchModal.type == 'none'" @tap.stop="">
			<view class="bg-white content text-bold text-pink padding-tb text-xl">小聚提醒您</view>
			<view class="padding text-left text-lg">您购买的商品不参与返佣</view>
			<view class="cu-bar bg-white justify-around action"><button class="cu-btn round bg-gray btnWidth" @tap="hideModal" hover-class="none">确 定</button></view>
		</view>
		<view class="cu-dialog" v-show="searchModal.type == 'login'" @tap.stop="">
			<view class="bg-white content text-bold text-pink padding-tb text-xl">小聚提醒您</view>
			<view class="flex justify-center padding text-left text-lg">为了保障您的收益，请先登录</view>
			<view class="cu-bar bg-white justify-around action">
				<button class="cu-btn round bg-gray btnWidth" @tap="hideModal" hover-class="none">取 消</button>
				<button class="cu-btn round bg-pink btnWidth" @tap="login" hover-class="none">登 录</button>
			</view>
		</view>
		<view class="cu-dialog" v-show="searchModal.type == 'version'" @tap.stop="">
			<view class="bg-white content text-bold text-pink padding-tb text-xl">小聚版本更新</view>
			<view class="flex justify-center padding text-left text-lg">有新版本可更新</view>
			<view class="cu-bar bg-white justify-around action">
				<button class="cu-btn round bg-gray btnHeight" @tap="hideUpdateVersionModal" hover-class="none">下次，谢谢</button>
				<button class="cu-btn round bg-pink btnHeight" @tap="updateVersion" hover-class="none">立刻更新</button>
			</view>
		</view>
		<view class="cu-dialog" v-show="searchModal.type == 'versionNow'" @tap.stop="">
			<view class="bg-white content text-bold text-pink padding-tb text-xl">小聚版本更新</view>
			<view class="flex justify-center padding text-left text-lg">有新版本可更新</view>
			<view class="cu-bar bg-white justify-around action"><button class="cu-btn round bg-pink btnHeight" @tap="updateVersion" hover-class="none">立刻更新</button></view>
		</view>
	</view>
</template>

<script>
import clipboard from '@/common/clipboard.js';
var _self;
export default {
	props: {
		searchModal: {
			type: Object,
			default() {
				return { type: '', pItem: [] };
			}
		}
	},
	computed: {
		searchContent() {
			return this.$store.state.searchContent;
		}
	},
	created() {
		_self = this;
	},
	methods: {
		goShare() {
			//分享
			if (_self.$util.Landing()) {
				if (_self.$util.ExistRelationId()) {
					let tmpitem = _self.searchModal.pItem;
					_self.hideModal();
					//跳转至分享页面
					uni.navigateTo({
						url: '../product/share?cnt=' + encodeURIComponent(JSON.stringify(tmpitem))
					});
				}
			} else {
				_self.searchModal.type = 'login';
			}
		},
		goProduct() {
			//查看详情
			let tmpitem = _self.searchModal.pItem;
			_self.hideModal();
			uni.navigateTo({
				url: '../product/main?cnt=' + encodeURIComponent(JSON.stringify(tmpitem))
			});
		},
		navTaobao() {
			//立即购买 去 淘宝
			if (_self.$util.Landing()) {
				if (_self.$util.ExistRelationId()) {
					//#ifdef APP-PLUS
					let tmpitem = _self.searchModal.pItem;
					_self.hideModal();
					setTimeout(() => {
						let plug = uni.requireNativePlugin('UZK-Alibcsdk');
						let url = tmpitem.promotedUrl + '&relationId=' + _self.$util.getRelationId();
						plug.init(result => {
							plug.openurl({
								url: url,
								linkkey: 'taobao',
								adzoneid: '103062550066',
								pid: 'mm_1159700186_1658850404_110381300098',
								nativeFailedMode: 'download',
								appkey: '29510703',
								opentype: 'native'
							});
						});
					}, 200);
					//#endif
				}
			} else {
				_self.searchModal.type = 'login';
			}
		},
		copyWord() {
			//复制淘口令
			//#ifdef MP-WEIXIN
			if (_self.$util.Landing()) {
				let tmpitem = _self.searchModal.pItem;
				_self.hideModal();
				_self.$util.taoKouLingCreate(tmpitem.promotedUrl).then(res => {
					uni.setClipboardData({
						data: res
					});
				});
			} else {
				_self.searchModal.type = 'login';
			}
			//#endif
		},
		login() {
			//确认登录
			_self.hideModal();
			uni.navigateTo({
				url: '../access/main'
			});
		},
		search() {
			let tmpcnt = this.$store.state.searchContent;
			_self.$util.setSearchHistory(tmpcnt, _self.$store.state.searchTBStorageHistory);
			_self.hideModal();
			uni.navigateTo({
				url: '../sou/list?cnt=' + encodeURIComponent(JSON.stringify(tmpcnt))
			});
		},
		//版本更新
		updateVersion() {
			_self.hideUpdateVersionModal();
			// #ifdef APP-PLUS
			if (plus.os.name == 'Android') {
				plus.runtime.openURL(_self.$store.state.androidUrl);
			} else {
				plus.runtime.openURL(_self.$store.state.iosUrl);
			}
			//#endif
		},
		//隐藏版本更新对话框
		hideUpdateVersionModal() {
			_self.$store.commit('updateVesion');
			_self.hideModal();
		},
		hideModal() {
			if (!_self.$store.state.version_force_update) {
				_self.searchModal.type = '';
				this.$emit('resetModal');
				//#ifdef APP-PLUS
				clipboard.setText('');
				//#endif
				//#ifdef MP-WEIXIN
				uni.setClipboardData({
					data: '',
					complete: function() {
						uni.hideToast();
					}
				});
				//#endif
				_self.$store.commit('hideSearchDialog');
			}
		}
	}
};
</script>

<style lang="scss">
.btnHeight {
	height: 80rpx;
}
.btnWidth {
	width: 200rpx;
	height: 80rpx;
}
.imgItem {
	display: flex;
	align-items: flex-start;
	.picItem {
		margin: 2rpx;
		width: 250rpx;
		height: 250rpx;
	}
}
.titleItem {
	display: -webkit-box;
	-webkit-box-orient: vertical;
	-webkit-line-clamp: 2;
	overflow: hidden;
	width: 100%;
}
.juanInfo {
	height: 70rpx;
	margin-top: 20rpx;
	width: 80%;
	padding-left: 20rpx;
	background-image: linear-gradient(45deg, #ec79be, #e83844);
	color: #fff;
	display: flex;
	justify-content: flex-start;
	align-items: center;
	border-radius: 6rpx;
}
</style>
